package com.example.lx5_27.visit

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.example.base.mvvm.BaseActivity
import com.example.lx5_27.R
import com.example.lx5_27.adapter.VisitAdapter
import com.example.lx5_27.databinding.ActivityVisitBinding
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch

@AndroidEntryPoint
@Route(path = "/app/VisitActivity")
class VisitActivity : BaseActivity<ActivityVisitBinding,VisitViewModel>() {

    var type = ""
    val visitAdapter by lazy { VisitAdapter() }
    override fun initView() {
        binding.rv.apply {
            adapter = visitAdapter
            layoutManager = LinearLayoutManager(this@VisitActivity)
        }
        lifecycleScope.launch {
            vm.getVisit("0","111").collect{
                visitAdapter.submitData(it)
            }
        }

        binding.rb1.setOnClickListener {
            type = "111"
            lifecycleScope.launch {
                vm.getVisit(type,"111").collect{
                    visitAdapter.submitData(it)
                }
            }
        }

        binding.rb2.setOnClickListener {
            type = "待审核"
            lifecycleScope.launch {
                vm.getVisit(type,"状态").collect{
                    visitAdapter.submitData(it)
                }
            }
        }

        binding.rb3.setOnClickListener {
            type = "已通过"
            lifecycleScope.launch {
                vm.getVisit(type,"状态").collect{
                    visitAdapter.submitData(it)
                }
            }
        }

        binding.rb4.setOnClickListener {
            type = "已拒绝"
            lifecycleScope.launch {
                vm.getVisit(type,"状态").collect{
                    visitAdapter.submitData(it)
                }
            }
        }

        binding.rb5.setOnClickListener {
            type = "已完成"
            lifecycleScope.launch {
                vm.getVisit(type,"状态").collect{
                    visitAdapter.submitData(it)
                }
            }
        }
    }

    override fun initData() {

    }
}